import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tverify/tverify.dart';

void main() {
  runApp(const MyApp());
}

/// app
class MyApp extends StatefulWidget {
  /// app
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Builder(
          builder: (context) {
            return Container(
              padding: MediaQuery.of(context).padding + const EdgeInsets.all(10),
              child: Wrap(
                spacing: 10,
                runSpacing: 10,
                children: [
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    child: const Text('initLogin'),
                    onPressed: () {
                      Tverify.initLogin('appId');
                    },
                  ),
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    child: const Text('preLogin'),
                    onPressed: () async {
                      try {
                        final map = await Tverify.preLogin();
                        debugPrint(map.toString());
                      } catch (e) {
                        debugPrint(e.toString());
                      }
                      debugPrint('object');
                    },
                  ),
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    child: const Text('login'),
                    onPressed: () async {
                      final map = await Tverify.login(UIDecorator.adaptive(
                        context,
                        userAgreement: (
                          name: '用户协议',
                          url: 'https://www.baidu.com',
                        ),
                        privacyPolicy: (
                          name: '隐私政策',
                          url: 'https://www.baidu.com',
                        ),
                        onClose: Tverify.dismissLogin,
                        onSwitch: Tverify.dismissLogin,
                      ));
                      await Tverify.dismissLogin();
                      debugPrint(map.toString());
                    },
                  ),
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    child: const Text('getSimInfo'),
                    onPressed: () async {
                      final simInfo = await Tverify.getSimInfo();
                      debugPrint(simInfo.toString());
                    },
                  ),
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    onPressed: Tverify.deleteScrip,
                    child: const Text('deleteScrip'),
                  ),
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    child: const Text('setTimeout'),
                    onPressed: () {
                      Tverify.setTimeout(const Duration(seconds: 1));
                    },
                  ),
                  CupertinoButton.filled(
                    borderRadius: BorderRadius.circular(5),
                    minSize: 40,
                    padding: const EdgeInsets.all(10),
                    onPressed: Tverify.dismissLogin,
                    child: const Text('dismissLogin'),
                  ),
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
